<?php

class UserModule extends CWebModule
{
    
	public function init()
	{
		// this method is called when the module is being created
		// you may place code here to customize the module or the application

		// import the module-level models and components
		$this->setImport(array(
			'User.models.*',
			'User.components.*',
		));
	}

	public function beforeControllerAction($controller, $action)
	{
		if(parent::beforeControllerAction($controller, $action))
		{
			// this method is called before any module controller action is performed
			// you may place customized code here
			return true;
		}
		else
			return false;
	}
    
    	/**
	 * @param $str
	 * @param $params
	 * @param $dic
	 * @return string
	 */
	public static function t($str='',$params=array(),$dic='user') {
		return Yii::t("UserModule.".$dic, $str, $params);
	}
	
	/**
	 * @return hash string.
	 */
	public static function encrypting($string="") {
		return md5(md5($string));
	}
    /**
	 * @return activation string.
	 */
	public static function activation($string="") {
		return md5($string);
	}
   
	/**
	 * @param $place
	 * @return boolean 
	 */
	public static function doCaptcha($place = '') {
		if(!extension_loaded('gd'))
			return false;
		if (in_array($place, Yii::app()->getModule('user')->captcha))
			return Yii::app()->getModule('user')->captcha[$place];
		return false;
	}
	 
     
  public static function getRandomSalt() {
        $length =   6;
        $char   =   "~!@#$%^&*()_+1234567890";
        $rand   =   "";
        for ($i=0; $i<$length; $i++) {
            $rand   .=  $char[rand(0, strlen($char)-1)];
        }
        return $rand;
    }
    
    
}
